{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "439ee564",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\ASUS\\\\bar_example.html'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Bar\n",
    "from pyecharts import options as opts\n",
    " \n",
    "# 创建Bar实例\n",
    "bar = Bar()\n",
    " \n",
    "# 添加数据\n",
    "bar.add_xaxis([\"A\", \"B\", \"C\", \"D\", \"E\", \"F\"])\n",
    "bar.add_yaxis(\"系列名称\", [10, 20, 30, 40, 50, 60])\n",
    " \n",
    "# 设置全局选项\n",
    "bar.set_global_opts(title_opts=opts.TitleOpts(title=\"柱状图示例\"))\n",
    " \n",
    "# 渲染图表到文件\n",
    "bar.render(\"bar_example.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b50eb134",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\ASUS\\\\南丁格尔玫瑰图.html'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pyecharts.charts import Pie\n",
    "from pyecharts import options as opts\n",
    " \n",
    "# 读入数据，需要更改\n",
    "df = pd.read_excel(r\"E:\\大三下数据分析课\\week16-18期末项目\\templates\\人气排序.xlsx\")\n",
    "df = df.sort_values(\"平均薪酬\")\n",
    "v = df['专业名'].values.tolist()\n",
    "d = df['平均薪酬'].values.tolist()\n",
    "# 设置颜色\n",
    "color_series = ['#FAE927', '#E9E416', '#C9DA36', '#9ECB3C', '#6DBC49',\n",
    "                '#37B44E', '#3DBA78', '#14ADCF', '#209AC9', '#1E91CA',\n",
    "                '#2C6BA0', '#2B55A1', '#2D3D8E', '#44388E', '#6A368B'\n",
    "                                                            '#7D3990', '#A63F98', '#C31C88', '#D52178', '#D5225B',\n",
    "                '#D02C2A', '#D44C2D', '#F57A34', '#FA8F2F', '#D99D21',\n",
    "                '#CF7B25', '#CF7B25', '#CF7B25']\n",
    "# 实例化Pie类\n",
    "pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px'))\n",
    "# 设置颜色\n",
    "pie1.set_colors(color_series)\n",
    "# 添加数据，设置饼图的半径，是否展示成南丁格尔图\n",
    "pie1.add(\"222\", [list(z) for z in zip(v, d)],\n",
    "         radius=[\"100%\", \"15%\"],\n",
    "         center=[\"60%\", \"50%\"],\n",
    "         rosetype=\"area\"\n",
    "         )\n",
    "# 设置全局配置项\n",
    "pie1.set_global_opts(title_opts=opts.TitleOpts(title='玫瑰图示例'),\n",
    "                     legend_opts=opts.LegendOpts(is_show=False),\n",
    "                     toolbox_opts=opts.ToolboxOpts())\n",
    "# 设置系列配置项\n",
    "pie1.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position=\"inside\", font_size=12,\n",
    "                                               formatter=\"{b}:{c}\", font_style=\"italic\",\n",
    "                                               font_weight=\"bold\", font_family=\"Microsoft YaHei\"\n",
    "                                               ),\n",
    "                     )\n",
    "# 生成html文档\n",
    "pie1.render(\"南丁格尔玫瑰图.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "283c0e1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\ASUS\\\\网新院校排名.html'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pyecharts.charts import Pie\n",
    "from pyecharts import options as opts\n",
    " \n",
    "# 读入数据，需要更改\n",
    "df = pd.read_excel(r\"E:\\大三下数据分析课\\week16-18期末项目\\templates\\网新专业.xlsx\")\n",
    "df = df.sort_values(\"学校排名\")\n",
    "v = df['学校名'].values.tolist()\n",
    "d = df['学校排名'].values.tolist()\n",
    "# 设置颜色\n",
    "color_series = ['#FAE927', '#E9E416', '#C9DA36', '#9ECB3C', '#6DBC49',\n",
    "                '#37B44E', '#3DBA78', '#14ADCF', '#209AC9', '#1E91CA',\n",
    "                '#2C6BA0', '#2B55A1', '#2D3D8E', '#44388E', '#6A368B'\n",
    "                                                            '#7D3990', '#A63F98', '#C31C88', '#D52178', '#D5225B',\n",
    "                '#D02C2A', '#D44C2D', '#F57A34', '#FA8F2F', '#D99D21',\n",
    "                '#CF7B25', '#CF7B25', '#CF7B25']\n",
    "# 实例化Pie类\n",
    "pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px'))\n",
    "# 设置颜色\n",
    "pie1.set_colors(color_series)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# 添加数据，设置饼图的半径，是否展示成南丁格尔图\n",
    "pie1.add(\"222\", [list(z) for z in zip(v, d)],\n",
    "         radius=[\"18%\", \"90%\"],\n",
    "         center=[\"40%\", \"70%\"],\n",
    "         rosetype=\"area\"\n",
    "         )\n",
    "# 设置全局配置项\n",
    "pie1.set_global_opts(title_opts=opts.TitleOpts(title='玫瑰图示例'),\n",
    "                     legend_opts=opts.LegendOpts(is_show=False),\n",
    "                     toolbox_opts=opts.ToolboxOpts())\n",
    "# 设置系列配置项\n",
    "pie1.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position=\"inside\", font_size=12,\n",
    "                                               formatter=\"{b}:{c}\", font_style=\"italic\",\n",
    "                                               font_weight=\"bold\", font_family=\"Microsoft YaHei\"\n",
    "                                               ),\n",
    "                     )\n",
    "# 生成html文档\n",
    "pie1.render(\"网新院校排名.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "06260dc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\ASUS\\\\汉语言院校排名.html'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Bar  # 柱状图\n",
    "from pyecharts.charts import Line # 折线图\n",
    "from pyecharts.globals import SymbolType\n",
    "from pyecharts import options as opts\n",
    "bar = Bar()\n",
    "kind = [\"北京师范大学\",\"南京大学\",\"北京大学\",\"复旦大学\",\"武汉大学\",\"四川大学\",\"华东师范大学\",\"浙江大学\",\"中国人民大学\",\"陕西师范大学\",]\n",
    "data1 = [1,2,3,4,5,6,7,8,9,10,]\n",
    "bar.add_xaxis(kind)\n",
    "# bar.add_yaxis(\"商家A\",data1)\n",
    "bar.add_yaxis(\"排名\",data1,category_gap = \"60%\") # 设置矩形宽度百分比\n",
    "# bar.set_colors([\"blue\",\"green\",\"yellow\",\"red\",\"pink\",\"orange\"]) # 颜色取第一个元素\n",
    "bar.set_global_opts(title_opts=opts.TitleOpts(title=\"\"))\n",
    "bar.reversal_axis() # 将坐标轴颠倒\n",
    "bar.set_series_opts(label_opts=opts.LabelOpts(position=\"right\"))\n",
    "bar.render(\"./汉语言院校排名.html\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "804cc64d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
